package com.huidu.bitrade.server;

import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.DescribeClusterOptions;
import org.apache.kafka.clients.admin.DescribeClusterResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Properties;

@Component
public class KafkaClient {

    @Value("${spring.kafka.bootstrap-servers:}")
    private String uri;
    public boolean client() {
        Properties props = new Properties();
        props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, uri);

        try (AdminClient adminClient = AdminClient.create(props)) {
            DescribeClusterOptions describeOptions = new DescribeClusterOptions().timeoutMs(5000);
            DescribeClusterResult describeResult = adminClient.describeCluster(describeOptions);
            describeResult.clusterId().get();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
